/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.service;

import java.util.List;
import java.util.Map;

import com.jeesite.modules.goods.entity.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.file.utils.FileUploadUtils;
import com.jeesite.modules.goods.dao.ZtGoodsDao;
import com.jeesite.modules.jdProduct.entity.Product;
import com.jeesite.modules.xcxAdmin.dao.ZtAdminDao;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;

/**
 * 测试数据Service
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Service
@Transactional(readOnly = true)
public class ZtGoodsService extends CrudService<ZtGoodsDao, ZtGoods> {
	@Autowired
	private ZtColorService ztColorService; 
	@Autowired
	private ZtGoodsquanService ztGoodsquanService;
	
	
	public String getImgFirst(ZtGoods ztGoods){
		return dao.getImgFirst(ztGoods);
	}
	
	@Transactional(readOnly = false)
	public void batchUpdate(List<ZtGoods> ztGoodsList) {
		dao.batchUpdate(ztGoodsList);
	}
	
	@Transactional(readOnly = false)
	public void batchUpdateSjStatus(List<ZtGoods> ztGoodsList) {
		dao.batchUpdateSjStatus(ztGoodsList);
	}
	@Transactional(readOnly = false)
	public void batchUpdateGoodstemp(List<ZtGoods> ztGoodsList) {
		dao.batchUpdateGoodstemp(ztGoodsList);
	}
	
	@Transactional(readOnly = false)
	public void saveContentimgs(ZtGoods ztGoods) {
		dao.saveContentimgs(ztGoods);
		
	}
	
	@Transactional(readOnly = false)
	public void batchUpdatePrice(List<ZtGoods> ztGoodsList) {
		dao.batchUpdatePrice(ztGoodsList);
		
	}
	
	
	public ZtGoods getGoodInfo(ZtGoods ztGoods){
		return dao.getGoodInfo(ztGoods);
	}
	
	public ZtGoods getGoodstemp(ZtGoods ztGoods){
		return dao.getGoodstemp(ztGoods);
	}
	
	public ZtGoods getByCode(ZtGoods ztGoods){
		return dao.getByCode(ztGoods);
	}
	
	
	
	public List<String> getImgs(ZtGoods ztGoods){
		return dao.getImgs(ztGoods);
	}
	public List<ZtGoods> findByTitle(ZtGoods ztGoods){
		return dao.findByTitle(ztGoods);
	}
	public List<ZtGoods> findListPageNum(ZtGoods ztGoods){
		return dao.findListPageNum(ztGoods);
	}
	
	
	public ZtGoods getmh(ZtGoods ztGoods){
		return dao.getmh(ztGoods);
	}
	
	public ZtGoods getDetail(ZtGoods ztGoods){
		return dao.getDetail(ztGoods);
	}
	
	public String getFileFirst(ZtGoods ztGoods){
		return dao.getFileFirst(ztGoods);
	}
	
	public List<Map> findMh(ZtGoods ztGoods){
		return dao.findMh(ztGoods);
	}
	
	
	public List<Map> findMainMh(ZtGoods ztGoods){
		return dao.findMainMh(ztGoods);
	}
	
	public List<Map> findMainPoster(ZtGoods ztGoods){
		return dao.findMainPoster(ztGoods);
	}
	
	
	/**
	 * 获取单条数据
	 * 
	 * @param testData
	 * @return
	 */
	@Override
	public ZtGoods get(ZtGoods ztGoods) {
		ZtGoods entity = super.get(ztGoods);
		if (entity == null) {
			entity = new ZtGoods();
		}
		return entity;
	}

	/**
	 * 查询分页数据
	 * 
	 * @param page
	 *          分页对象
	 * @param testData
	 * @return
	 */
	@Override
	public Page<ZtGoods> findPage(Page<ZtGoods> page, ZtGoods ztGoods) {
	
		return super.findPage(page, ztGoods);
	}
	
	public Page<ZtGoods> findAutoPage(Page<ZtGoods> page, ZtGoods ztGoods) {
		ztGoods.setPage(page);
		page.setList(dao.findAutoList(ztGoods));
		return page;
	}
	
	/**
	 * 保存数据（插入或更新）
	 * 
	 * @param testData
	 */
	/**
	 * 保存数据（插入或更新）
	 * 
	 * @param testData
	 */
	@Override
	@Transactional(readOnly = false)
	public void save(ZtGoods ztGoods) {
		
		String ztGoodsid=ztGoods.getZtGoodsid();
		
		super.save(ztGoods);
		
		if(StringUtils.isNotBlank(ztGoodsid)){
			ZtColor ztColor=new ZtColor();
			ZtGoods zg=new ZtGoods();
			zg.setId(ztGoodsid);
			ztColor.setZtGoods(zg);
			ztColor.setZtGoodsid(ztGoods.getId());
			ztColorService.updateZtGoodsid(ztColor);
		
		}
		
		ZtColor ztColor=new ZtColor();
		ZtGoods zg=new ZtGoods();
		zg.setId(ztGoods.getId());
		ztColor.setZtGoods(zg);
		
		int count=ztColorService.findNumCount(ztColor);
		
		ztGoods.setCount(count);
		
		ztGoods.setIsNewRecord(false);
		super.save(ztGoods);
		
		// 保存上传图片   bizKey="${ztGoods.id}" bizType="user_upload1"
		FileUploadUtils.saveFileUpload(ztGoods.getId(), "user_upload1");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(ztGoods.getId(), "user_upload2");
		
		FileUploadUtils.saveFileUpload(ztGoods.getId(), "user_upload3");
		
		FileUploadUtils.saveFileUpload(ztGoods.getId(), "user_upload10");
		
	}

	/**
	 * 更新状态
	 * 
	 * @param testData
	 */
	@Override
	@Transactional(readOnly = false)
	public void updateStatus(ZtGoods ztGoods) {
		super.updateStatus(ztGoods);
	}
	@Transactional(readOnly = false)
	public void updateState(GoodsType goodsType) {
		dao.updateState(goodsType);
	}
	@Transactional(readOnly = false)
	public void updateStateDis(List<String> goodscodes) {
		dao.updateStateDis(goodscodes);
	}
	
	
	@Transactional(readOnly = false)
	public void updateSjStatus(ZtGoods ztGoods) {
		dao.updateSjStatus(ztGoods);
	}

	/**
	 * 删除数据
	 * 
	 * @param testData
	 */
	@Override
	@Transactional(readOnly = false)
	public void delete(ZtGoods ztGoods) {
		super.delete(ztGoods);
	}

	@Transactional(readOnly = false)
	public void updateSjStatusType(GoodsType goodsType) {
		dao.updateSjStatusType(goodsType);
	}
	
	public List<ZtGoods> findMoreMh(ZtGoods ztGoods){
		return dao.findMoreMh(ztGoods);
	}
	
	public List<Map> findMhByType(ZtGoods ztGoods){//分类
		return dao.findMhByType(ztGoods);
	}
	
	public List<Map> findMhByTypeByFirst(ZtGoods ztGoods){//分类
		return dao.findMhByTypeByFirst(ztGoods);
	}
	@Transactional(readOnly = false)
	public int updateSoldOut(){
		return dao.updateSoldOut();
	}
	public List<ZtGoods> getGoodsPricing(String [] list){
		return dao.getGoodsPricing(list);
	}
}